home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / distutils / dep_util.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  3.1 KB  |  77 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''distutils.dep_util
  5.  
  6. Utility functions for simple, timestamp-based dependency of files
  7. and groups of files; also, function based entirely on such
  8. timestamp dependency analysis.'''
  9. __revision__ = '$Id: dep_util.py 58049 2007-09-08 00:34:17Z skip.montanaro $'
  10. import os
  11. from distutils.errors import DistutilsFileError
  12.  
  13. def newer(source, target):
  14.     """Return true if 'source' exists and is more recently modified than
  15.     'target', or if 'source' exists and 'target' doesn't.  Return false if
  16.     both exist and 'target' is the same age or younger than 'source'.
  17.     Raise DistutilsFileError if 'source' does not exist.
  18.     """
  19.     if not os.path.exists(source):
  20.         raise DistutilsFileError, "file '%s' does not exist" % os.path.abspath(source)
  21.     os.path.exists(source)
  22.     if not os.path.exists(target):
  23.         return 1
  24.     ST_MTIME = ST_MTIME
  25.     import stat
  26.     mtime1 = os.stat(source)[ST_MTIME]
  27.     mtime2 = os.stat(target)[ST_MTIME]
  28.     return mtime1 > mtime2
  29.  
  30.  
  31. def newer_pairwise(sources, targets):
  32.     """Walk two filename lists in parallel, testing if each source is newer
  33.     than its corresponding target.  Return a pair of lists (sources,
  34.     targets) where source is newer than target, according to the semantics
  35.     of 'newer()'.
  36.     """
  37.     if len(sources) != len(targets):
  38.         raise ValueError, "'sources' and 'targets' must be same length"
  39.     len(sources) != len(targets)
  40.     n_sources = []
  41.     n_targets = []
  42.     for i in range(len(sources)):
  43.         if newer(sources[i], targets[i]):
  44.             n_sources.append(sources[i])
  45.             n_targets.append(targets[i])
  46.             continue
  47.     
  48.     return (n_sources, n_targets)
  49.  
  50.  
  51. def newer_group(sources, target, missing = 'error'):
  52.     '''Return true if \'target\' is out-of-date with respect to any file
  53.     listed in \'sources\'.  In other words, if \'target\' exists and is newer
  54.     than every file in \'sources\', return false; otherwise return true.
  55.     \'missing\' controls what we do when a source file is missing; the
  56.     default ("error") is to blow up with an OSError from inside \'stat()\';
  57.     if it is "ignore", we silently drop any missing source files; if it is
  58.     "newer", any missing source files make us assume that \'target\' is
  59.     out-of-date (this is handy in "dry-run" mode: it\'ll make you pretend to
  60.     carry out commands that wouldn\'t work because inputs are missing, but
  61.     that doesn\'t matter because you\'re not actually going to run the
  62.     commands).
  63.     '''
  64.     if not os.path.exists(target):
  65.         return 1
  66.     ST_MTIME = ST_MTIME
  67.     import stat
  68.     target_mtime = os.stat(target)[ST_MTIME]
  69.     for source in sources:
  70.         source_mtime = os.stat(source)[ST_MTIME]
  71.         if source_mtime > target_mtime:
  72.             return 1
  73.     else:
  74.         return 0
  75.     return source_mtime > target_mtime
  76.  
  77.